<!--鼓浪屿首页备份文件-->
<? 
define('PC', 1);
define('NO_CACHE', true);
include("ggheader.php");
include_once("/var/www/html/new/com.inc.php");
include_once('/var/www/html/wx/api/v0.0.1/init.php');
define('DETAIL_LINK','/new/d/shops/gdetail.html');// 详情链接地址
$showProdTmp = $saveArr['products']['A']['5322'];
$types = array(
    'A'=>'景区门票',
    'B'=>'旅游路线',
    'C'=>'酒店预定',
);
$urls = array(
    'A'=>'gtTicket.html',
    'B'=>'groute.html',
    'C'=>'ghlist.html',
);
// 下架产品    景点介绍
$soap     = SoapInit::GetSoapInside();
function salePros($apply_did,$lid=Null){

	$account = ($_SESSION['saccount']) ? $_SESSION['saccount']:$_SESSION['account'];
	$r=array();
	$salePids=array();
	$str="select tid,aid,dprice from uu_priceset where pid={$apply_did}";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$dprices[$row['tid']."_".$row['aid']]=$row['dprice'];
	}
	$sql=<<<SQL
select p.id as pid,p.apply_did,p.p_status,l.id as lid,l.p_type,l.areacode,
l.title,getPY(l.title,1) as py,l.area,l.topic,l.px,l.runtime,l.taobao_support,l.imgpath,
l.address,t.id as tid,t.pay,t.getaddr,t.title as ttitle,t.tprice,t.notes,
t.buy_limit_low,t.ddays,t.delaydays,t.status,f.ass_station,
f.mdays,f.mhour,f.rdays,t.order_end,t.delaytype,t.sync_status
from uu_products p left join uu_land l on p.contact_id=l.id left join
uu_jq_ticket t on p.id=t.pid left join uu_land_f f on f.pid=p.id
SQL;
	$where="where p.p_status=0 and p.apply_limit=2";
	if($lid) $where.=" and l.id=$lid ";
	$orderby=" order by l.px desc ";
	/*一手供应商产品*/
	$aids=array(0=>$apply_did);
	$str="SELECT l.pids,l.aid FROM pft_product_sale_list l LEFT JOIN pft_member m ON l.aid=m.id WHERE l.fid={$apply_did} AND l.status=0 AND m.status=0";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$salePids[$row['aid']]=explode(",",$row['pids']);
		$aids[]=$row['aid'];
	}
	if(count($aids)!=0){
		$aids=implode(",",$aids);
		$where1=$where." AND p.apply_did in ($aids) ";
		$str1="$sql $where1 $orderby";
		$GLOBALS['le']->query($str1);
		while($row=$GLOBALS['le']->fetch_assoc()){
			if($row['apply_did']!=$apply_did
				&&$salePids[$row['apply_did']][0]!="A"
				&&!in_array($row['pid'],$salePids[$row['apply_did']]))
			{
				continue;
			}
			$row['sapply_did']=$row['apply_did'];
			$row['aid']=0;
			$row['lvl']=0;
			$r[]=$row;
		}
	}
	/*二手供应商产品*/
	$str="select pid,sid from pft_p_apply_evolute where fid={$apply_did} and status=0 and sid<>sourceid";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$secondInfo[$row['pid']."_".$row['sid']]=$row;
		$secondPids[]=$row['pid'];
	}
	if(count($secondPids)!=0){
		$proInfo    = array();
		$secondPids = implode(",",$secondPids);
		$where2     = $where." and p.id in ($secondPids) ";
		$str2       = "$sql $where2 $orderby";
		$GLOBALS['le']->query($str2);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$proInfo[$row['pid']]=$row;
		}
		foreach($secondInfo as $key=>$value){
			list($pid, $sapply_did) = explode("_",$key);
			if(!$proInfo[$pid]) continue;
			$row    = $proInfo[$pid];
			$row['sapply_did']=$sapply_did;
			$row['aid']=$sapply_did;
			$row['lvl']=$value['lvl'];
			$row['eid']=$value['id'];
			$row['estatus']=$value['status'];
			$aids   = explode(",",$value['aids']);
			$aids[] = $value['fid'];
			$aids[0]=0;
			$r[]=$row;
		}
	}
	return $r;
}

$salePros = salePros($_SESSION['domain_mid']);
$saveArr  = array();
//获取分销商account，价格接口需要
$sql = "SELECT account FROM pft_member WHERE id='".($IdentityFlag ? $_SESSION['sid'] : $apply_did)."' LIMIT 1";
//echo $sql;
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
$ac = $GLOBALS['le']->f('account');

foreach ($salePros as $pros) {
	$area       = explode("|",$pros['area']);
	$tuijian    = $pros['px'];
	//$price = getPrice($soap, $Y_m_d, $pros['pid'], $pros['sapply_did']);
	if($pros['apply_did']==$apply_did){
		$tuijian += 100;
	}
	//和分销商同一地区的，排名靠前
	if ($area[0] == $province || $area[1]==$city ) {
		$tuijian += 100;
	}
	$row['tuijian'] = $tuijian;

	$jsprice = 1;
	$jsprice = 1 ;

	$imgpath = strpos($pros['imgpath'], 'http')!==false ? $pros['imgpath']
		: 'http://www.12301.cc/' . $pros['imgpath'];
	$products[$pros['p_type']][$pros['lid']] = array(
			'id'     => $pros['lid'],
			'title'  => $pros['title'],
			'addr'   => $pros['address'],
			'area'   => $areas[$area[0]].'|'
						.$areas[$area[1]] . '|'.$areas[$area[2]],
			'ptype'  => $pros['p_type'],
			'imgpath'=> $imgpath,
			'px'     => $pros['px'],
			'opentime'=> $pros['runtime'],
			'areacode'=> $pros['areacode'],
			'tuijian'=> $tuijian,
	);
	$useTime     = $pros['delaydays']>0?
						"游玩日期起{$pros['delaydays']}天内有效":"游玩日期当日有效";
//        echo "$ac,{$pros['pid']},$Y_m_d,1,0,0,{$pros['sapply_did']}";

	$tickets[$pros['lid']][] = array(
		'pid'       => $pros['pid'],
		'aid'       => $pros['aid'],
		'tid'       => $pros['tid'],
		'title'     => $pros['ttitle'],
		'tprice'    => $pros['tprice']*100 / 100,
		'jsprice'   => $jsprice/100,
		'uprice'    => $uprice/100,
		'sapply_did'=> $pros['sapply_did'],
		'pay'       => $pros['pay'],
		'bookTimeDay'   => $pros['ddays'] ,
		'bookTimeHour'  => $pros['dhour'],
		'getaddr'   => $pros['getaddr'],
		'notes'     => $pros['notes'],
		'usetime'   => $useTime,
		'p_type'    => $pros['p_type'],
	);
	$priceArr[$pros['lid']][]  = $jsprice/100;
	$uPriceArr[$pros['lid']][] = $uprice/100;
}
if (count($products)>0) {
	//推入最小价格
	foreach ($products as $ptype=>$product) {
		array_walk($products[$ptype], function(&$item,$key) use ($priceArr, $uPriceArr){
			if ($key=='total') return;
			$item['jsprice']   = min($priceArr[$key]);
			$item['uprice']    = min($uPriceArr[$key]);
		});
		//计算总数
		$products[$ptype]['total'] = count($product);
	}

	//print_r($products);
	//排序下
	uasort($products,  function($a,$b){
		$tuijiana = $a['tuijian'];
		$tuijianb = $b['tuijian'];
		if ($tuijiana==$tuijianb){
			$pxa=$a['px'];
			$pxb=$b['px'];
			if($pxa==$pxb) return 0;
			return ($pxa>$pxb) ? -1 : 1;
		}else{
			return ($tuijiana>$tuijianb) ? -1 : 1;
		}
	});
}

$saveArr = array(
	'products'=> $products,
	'tickets' => $tickets,
);
$unShow = array('A','G','B','C');
$hot = $saveArr['products']['A'];
$saveArr['products']['F']['5322'] = $showProdTmp;
unset($saveArr['products']['A']['5322']);
if(count($hot)){
    shuffle($hot);
    ksort($saveArr['products']);
}
?>
<div id="ggBanner" class="ggBanner">
    <div class="bstage">
        <ul class="slideUl">
            <li class="sitem"><a href="#"><img src="<?=$shop['M_banner']?>" alt=""/></a></li>
        </ul>
    </div>
    <div class="bnavCon">
        <div class="ggw1100 bnavInn">
        </div>
    </div>
</div>
<div class="ggMainCon ggw1100 clearfix">
    <div class="mainCol l">

    <?foreach($saveArr['products'] as $ky =>$products):?>
    <?if($ky!='F') continue; ?>
    <?$count = count($products)>3 ? 3:count($products); ?>
    <div class="gglistGroup col-<?=$count?> clearfix">
        <div class="gghd"><h3 class="col l">套票产品</h3></div>
        <ul class="listUl clearfix">
            <?$i=0;?>
            <?foreach($products as $key=>$data):?>
            <?if((++$i)>6 || $key=='total') break;?>
            <?if($data['px']<0) continue;?>
            <li class="ggListItem">
                <div class="photo"><a href="<?=DETAIL_LINK.'?lid='.$key?>"><img src="<?=$data['imgpath']?>" alt="<?=$data['title']?>"/></a></div>
                <div class="bCon">
                    <a class="awrap" href="<?=DETAIL_LINK.'?lid='.$key?>">
                        <span class="tit ggellipsis"><?=$data['title']?></span>
                        <!--<span class="desc ggellipsis">描述</span>-->
                        <span class="fw clearfix">
                            <span class="col price l">
                                <span class="p p1">原价：<i class="yen">&yen;</i><span class="num"><?=$data['uprice']+10?></span></span>
                                <span class="p p2">预订价：<i class="yen">&yen;</i><span class="num"><?=$data['uprice']?></span></span>
                            </span>
                            <span class="col online r">在线预订</span>
                        </span>
                    </a>
                </div>
            </li>
            <?endforeach;?>
        </ul>
    </div>
    <?endforeach;?>
    <!--鼓浪屿定制开始-->
    <?foreach($saveArr['products'] as $ky =>$products):?>
    <?if($ky!='A') continue; ?>
    <?$count = count($products)>3 ? 3:count($products); ?>
    <div class="gglistGroup col-<?=$count?> clearfix">
        <div class="gghd"><h3 class="col l">景点简介</h3></div>
        <ul class="listUl clearfix">
            <?$i=0;?>
            <?foreach($products as $key=>$data):?>
            <?if((++$i)>6 || $key=='total') break;?>
            <?if($data['px']<0) continue;?>
            <li class="ggListItem">
                <div class="photo"><a href="<?=DETAIL_LINK.'?lid='.$key?>" ><img src="<?=$data['imgpath']?>" alt="<?=$data['title']?>"/></a></div>
                <div class="bCon">
                    <a class="awrap" href="<?=DETAIL_LINK.'?lid='.$key?>" >
                        <span class="tit ggellipsis"><?=$data['title']?></span>
                        <!--<span class="desc ggellipsis">描述</span>-->
                        <!--
                        <span class="fw clearfix">
                            <span class="col price l">
                                <span class="p p1">原价：<i class="yen">&yen;</i><span class="num"><?=$data['uprice']+10?></span></span>
                                <span class="p p2">预订价：<i class="yen">&yen;</i><span class="num"><?=$data['uprice']?></span></span>
                            </span>
                            <span class="col online r">在线预订</span>
                        </span>
                        -->
                    </a>
                </div>
            </li>
            <?endforeach;?>
        </ul>
    </div>
    <?endforeach;?>
    <!--鼓浪屿定制结束-->
    
    </div>
    <div class="ggNoticeBar mainCol r">
        <div id="newsContainer" class="nbox sucOrder sucOrderBar">
            <p class="tit"><i class="gsprite gicon sucOrder"></i><span class="t">系统通知</span></p>
            <div id="newsSlideStage" class="conWrap">
                 <ul id="newsSlideListUl" class="listUl">
                </ul>
            </div>
        </div>
	    <div style="margin-top:10px;" id="sucOrderList" class="nbox sucOrder sucOrderBar">
		    <p class="tit"><i class="gsprite gicon sucOrder"></i><span class="t">预订成功</span></p>
            <div id="" class="conWrap">
                 <ul id="" class="listUl">
                    <?for($i=0;$i<3;$i++):?>
	                 <li><span class="t">2014/12/20 20:30:26</span><span class="user">张*全</span><span class="suc">成功预订</span><a href="#" class="pn">鼓浪屿核心景点套票成人票</a></span></li>
	                 <?endfor;?>
                </ul>
            </div>
	    </div>
    </div>
	
    <div class="mbanner"><a href="#"><img src="http://www.12301.cc/shops/asset/mbanner140.png" alt=""/></a></div>
</div>
<script type="text/javascript">
	$(function(){
		G.News.init("#newsContainer");
		G.SucOrderNews.init("#sucOrderList");
	})

</script>
<?php include("ggfoot.php");?>
</body>